package com.e3.sysmg.security.client;

import com.e3.sysmg.security.model.ModuleModel;
import com.e3.template.tgf.TGFEditorDialog;
import com.e3.template.tgf.TGFSimpleFormPanel;
import com.e3.web.core.client.GwtAsyncCallback;
/**
 * Module模块的编辑窗口。
 * 新建和修改都使用该窗口。
 * @author Janty
 *
 */
public class ModuleEditorDialog extends TGFEditorDialog<ModuleModel> {
	
	private ModuleRPCServiceAsync service = ModuleRPCService.Util.getInstance();

	@Override
	public String checkOnSave(ModuleModel model) {
		String code = model.getCode();
		String name = model.getName();
		
		StringBuffer msgs = new StringBuffer();
		if (code == null || code.trim().length() == 0) {
			msgs.append(ModuleFieldsConstant.INSTANCE.module_code()+",");
		}
		
		if (name == null || name.trim().length() == 0) {
			msgs.append(ModuleFieldsConstant.INSTANCE.module_name()+",");
		}
				
		String s  = null;
		if(msgs.length()>0){
			s = msgs.substring(0,msgs.length()-1);
		}
		if(s != null){
			return ModuleMessages.INSTANCE.msg_notnull(s);
		}
		return null;
	}

	@Override
	public TGFSimpleFormPanel<ModuleModel> createFormPanel() {
		return new ModuleFormPanel();
	}

	@Override
	public void executeNewService(ModuleModel model,GwtAsyncCallback<ModuleModel> callback) {
		service.newModule(model, callback);
	}

	@Override
	public void executeModifyService(ModuleModel model,	GwtAsyncCallback<ModuleModel> callback) {
		service.modifyModule(model, callback);
	}

	@Override
	public String[] getNotNullFieldNames() {
		return null;
	}
	

}
